package dxunderground.TestData;

import java.io.EOFException;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.Vector;

public class ObjSerializationRead {

	/**
	 * Purpose:
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		ObjectInputStream ois = null;
		Vector<Employee> empList = new Vector<Employee>();

		try {
			FileInputStream fis = new FileInputStream("EmployeeObjData");

			ois = new ObjectInputStream(fis);

			// available method does not always work correctly
			while (true) {
				Object obj = ois.readObject();

				System.out.println(obj.getClass().getName());

				if (obj instanceof Employee) {
					Employee emp = (Employee) obj;
					empList.add(emp);
				}
			}

		} catch (EOFException ex) {
			// do nothing in here - expected situation
		} catch (ClassNotFoundException ex) {
			System.out.println(ex);
		} catch (IOException ex) {
			// catches FileNotFoundException here as well
			System.out.println(ex);
		} finally {
			if (ois != null) {
				try {
					ois.close();
				} catch (IOException e) {
					e.printStackTrace();
				}

			}
		}

		// Collections.sort( empList );
		for (Employee e : empList) {
			System.out.println(e);
		}
	}

}
